package springJms.producer.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.annotation.Resource;
import javax.jms.*;


import springJms.producer.ProducerService;

public class ProducerServiceImpl implements ProducerService {

	@Autowired
	JmsTemplate jmsTemplate;

	/*@Resource(name = "queueDestination")
	Destination destination;*/
	@Resource(name = "topicDestination")
    Destination destination;

	@Override
	public void sendMessage(String message) {
		jmsTemplate.send(destination, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                TextMessage textMessage = session.createTextMessage(message);
                System.out.println("发送消息 = [" + textMessage.getText() + "]");
                return textMessage;
            }
        });

	}

}
